<%--
  Created by IntelliJ IDEA.
  User: YuanDali
  Date: 2020/7/24
  Time: 18:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../back/js/html5shiv.js"></script>
    <script type="text/javascript" src="../back/js/respond.min.js"></script>
    <![endif]-->
    <link href="../back/css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="../back/css/H-ui.login.css" rel="stylesheet" type="text/css" />
    <link href="../back/css/style.css" rel="stylesheet" type="text/css" />
    <link href="../back/css/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="../back/js/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>贾楼影院后台登录</title>
    <meta name="keywords" content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
    <meta name="description" content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<input type="hidden" id="TenantId" name="TenantId" value="" />
<div class="header"></div>
<div class="loginWraper">
    <div id="loginform" class="loginBox">
        <form class="form form-horizontal" action="index.html" method="post">
            <div class="row cl">
                <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60d;</i></label>
                <div class="formControls col-xs-8">
                    <input id="adminId" name="adminId" type="text" placeholder="账户" class="input-text size-L">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60e;</i></label>
                <div class="formControls col-xs-8">
                    <input id="password" name="password" type="password" placeholder="密码" class="input-text size-L">
                </div>
            </div>
            <div class="row cl">
                <div class="formControls col-xs-8 col-xs-offset-3">
                    <input class="input-text size-L" id="verifyNumber" type="text" style="width: 150px" placeholder="验证码" onblur="if(this.value==''){this.value='验证码:'}" onclick="if(this.value=='验证码:'){this.value='';}" value="验证码:" style="width:150px;">
                    <img src="${pageContext.request.contextPath}/admin/getVerifyCode" id="getVerifyCodeImg"> <a id="kanbuq" href="javascript:;">看不清，换一张</a> </div>
            </div>
            <div class="row cl">
                <div class="formControls col-xs-8 col-xs-offset-3">
                    <label for="online">
                        <input type="checkbox" name="online" id="online" value="">
                        记住密码</label>
                </div>
            </div>
            <div class="row cl">
                <div class="formControls col-xs-8 col-xs-offset-3">
                    <button name="" type="button" id="adminButt" class="btn btn-success radius size-L" value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;">&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;</button>
                    <input name="" type="reset" id="cancelLogin" class="btn btn-default radius size-L" value="&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;">
                </div>
            </div>
        </form>
    </div>
</div>
<div class="footer">贾楼影院后台管理系统</div>
<script type="text/javascript" src="../back/js/jquery.min.js"></script>
<script type="text/javascript" src="../back/js/H-ui.min.js"></script>
</body>
<script>
    $(document).ready(function () {
        //进页面后先获取本地存储的账号信息
        //判断有没有该管理员信息
        if (window.localStorage.length!=0){
            //说明有本地存储密码
            var adminId = window.localStorage.key(0);
            var password = window.localStorage.getItem(adminId);
            //填充管理员id
             $("#adminId").val(adminId);
            //填充管理员密码
             $("#password").val(password);
        }
        //对账号输入框做失去焦点事件
        $("#adminId").blur(function () {
            //获取管理员id
            var adminId = $("#adminId").val();
            //从本地缓存中获取账号的密码
            var password = window.localStorage.getItem(adminId);
            //将该密码填充到密码框中
            $("#password").val(password);
        });

        //对登录按钮做点击事件
        $("#adminButt").click(function () {
            //获取管理员id
            var adminId = $("#adminId").val();
            //获取管理员密码
            var password = $("#password").val();
            //获取输入的验证码
           var verify = $("#verifyNumber").val();
           //获取session中的验证码
                //发送ajax请求
                $.ajax({
                    async:true,
                    url:"${pageContext.request.contextPath}/admin/adminLogin",
                    data:{
                        adminId:adminId,
                        password:password,
                        verify,verify
                    },
                    type:"get",
                    dataType:"json",
                    success:function (result) {
                        console.log(result);
                        if (result.code=="yes") {
                            //判断用户是否登录成功
                            if (result.adminObject=="yes"){
                                //登录成功后判断是否管理员是否记住密码
                                if ($("#online").is(":checked")) {
                                    //选中密码时将账号和密码储存在localStorage中
                                    window.localStorage.setItem(adminId,password);
                                }else{
                                    //清除保存在本地中的用户名和密码
                                    window.localStorage.removeItem(adminId);
                                }
                                if (result.adminType=="superAdmin") {
                                    //超级管理员登录，跳转到超级管理员界面
                                    window.location.href="user-manage.jsp";
                                }
                                if (result.adminType=="commonAdmin") {
                                    //超级管理员登录，跳转到普通管理员界面
                                    window.location.href="movie_back.jsp";
                                }
                            }else{
                                //负责登录失败，提示账户或密码错误
                                alert("账户或密码错误");
                            }
                        }else{
                            alert("验证码错误，请重新输入");
                        }
                    },
                    error:function () {
                        console.log("ajax请求失败");
                    }
                });
        });

        //对取消按钮做点击事件
        $("#cancelLogin").click(function () {
            //清空密码框中的密码
            $("#password").val("");
        });

    });//入口函数结束

    //对看不清换一张做点击事件
    $("#kanbuq").click(function () {
        //每点击一次就对验证码重新获取一次
     $("#getVerifyCodeImg").prop("src","${pageContext.request.contextPath}/admin/getVerifyCode?"+ new Date().getTime()+"");
        var verifySession = "${sessionScope.code}";
    });
</script>
</html>
